﻿// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    var canvas, context;
    var gameStage;
    var preloadQ;
    var logoScreenImage, backgroundImage;
    var logoScreenBitmap, backgroundBitmap;
    var soldier;
    var airplan;
    var tank;
    var ship;


    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize
                // your application here.
            } else {
                // TODO: This application has been reactivated from suspension.
                // Restore application state here.
            }
            args.setPromise(WinJS.UI.processAll());
        }
    };

    app.oncheckpoint = function (args) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // args.setPromise().
    };

    document.addEventListener("DOMContentLoaded", initialize, false);

    app.start();

    function Soldier() {
        this.rate_fire;	
        this.damage;
        this.range;
        this.mobility;
        this.health;
        this.elusiveness;
    }

    function Tank() {
        this.rate_fire;
        this.damage;
        this.range;
        this.mobility;
        this.health;
        this.elusiveness;
    }

    function Airplan() {
        this.rate_fire;
        this.damage;
        this.range;
        this.mobility;
        this.health;
        this.elusiveness;
    }

    function Ship() {
        this.rate_fire;
        this.damage;
        this.range;
        this.mobility;
        this.health;
        this.elusiveness;
    }

    function initialize() {
        canvas = document.getElementById("gameCanvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        context = canvas.getContext("2d");

        gameStage = new createjs.Stage(canvas);
       
        loadContent();
    }
     
    function loadContent() {
        preloadQ = new createjs.LoadQueue();   //ตัวที่จะเก็บทรัพยากรทั้งหมดของเกม เวลาจะใช้งานก็สามารถเรียกจากตัวนี้ได้
        preloadQ.on("complete", prepareStage, this);  //preloadQ จะเรียกฟังก์ชัน prepareStage
        // complete เป็นตัวที่บอกว่าเมื่อดาวน์โหลดเสร็จให้เรียกฟังก์ชันที่บอกไว้(prepareStage)

        preloadQ.loadManifest([  //ฟังก์ชันที่มีรายการที่จะโหลดทั้งหมด เก็บไว้เป็นอาร์เรย์
            { id: "logoScreen", src: "images/logoscreen.jpg" },
            { id: "background", src: "images/background.png" }
        ]);
         
    }

    function prepareStage() {
        logoScreenImage = preloadQ.getResult("logoScreen");
        logoScreenBitmap = new createjs.Bitmap(logoScreenImage);  //การที่จะใช้รูปในเกม ต้องใช้ bitmap (จุดของพิกเซล)
        gameStage.addChild(logoScreenBitmap);

        backgroundImage = preloadQ.getResult("background");
        backgroundBitmap = new createjs.Bitmap(logoScreenImage);  //การที่จะใช้รูปในเกม ต้องใช้ bitmap (จุดของพิกเซล)
        gameStage.addChild(backgroundBitmap);
    }
     
    function gameLoop() {
        update();
        draw();
    }
    
    function update() {
        
    }
      
    function draw() {
        gameStage.update();
    }

  
})();
